#include "Common.glsl"


#if VERTEX
    uniform mat4 worldViewProj;
    uniform mat4 worldView;
    uniform vec4 nearFarPlanes; // (near, far, 1/near, 1/far)
    
    in layout(location = POSITION) vec3 in_position;
    in layout(location = NORMAL) vec3 in_normal;
    
    out vec4 normal_linearDepth;

    void main()
    {
        vec4 pos4 = vec4(in_position, 1);
        vec4 viewPos = worldView * pos4;
        gl_Position = worldViewProj * pos4;
        normal_linearDepth.xyz = (worldView * vec4(in_normal, 0)).xyz;
        normal_linearDepth.w = -viewPos.z * nearFarPlanes.w;
    }
#endif


#if FRAGMENT
    in vec4 normal_linearDepth;
    out vec4 out_colour[2];
    
    void main()
    {
        out_colour[0] = PackFloat(normal_linearDepth.w);
        out_colour[1] = vec4(0.5 + 0.5*normal_linearDepth.xyz, 1);
    }
#endif
